/*
A Changer
control_D
title_D
trigger_D
score_D

zone_D

cap_active_D

*/


while {true} do {
sleep dure_cap;

//////////////////// ACTIF //////////////////////////////////////////////////////////////
if ((control_C == 1) && (control_E == -1))  then { // Zone C ATT et Zone E DEF
cap_active_D = true;
_type = getMarkerType "title_D"; if (_type != "selector_selectedMission") then {"title_D" setMarkerType "selector_selectedMission"};
};
////////////////////////////////////////////////////////////////////////////////////////

//////////////////// BLOQUER //////////////////////////////////////////////////////////
if ((control_C == 0) or (control_E == 0)) then { // Zone C ou E neutre
cap_active_D = false;
_type = getMarkerType "title_D"; if (_type != "selector_selectable") then {"title_D" setMarkerType "selector_selectable"};
};
////////////////////////////////////////////////////////////////////////////////////////

//////////////////// VERROUILLER ///////////////////////////////////////////////////////
if ((control_C == -1) && (control_D == -1))  then { // C et D DEF => verrouiller par DEF
cap_active_D = false;
score_D = -100;
_color = getMarkerColor "zone_D"; if (_color != "ColorRed") then {"zone_D" setMarkerColor "colorRed"};
_color = getMarkerColor "title_D"; if (_color != "ColorRed") then {"title_D" setMarkerColor "colorRed"};
_type = getMarkerType "title_D"; if (_type != "mil_box") then {"title_D" setMarkerType "mil_box"};
};

if ((control_D == 1) && (control_E == 1))  then { // D et E ATT => verrouiller par ATT
cap_active_D = false;
score_D = 100;
_color = getMarkerColor "zone_D"; if (_color != "ColorBlue") then {"zone_D" setMarkerColor "colorBlue"};
_color = getMarkerColor "title_D"; if (_color != "ColorBlue") then {"title_D" setMarkerColor "colorBlue"};
_type = getMarkerType "title_D"; if (_type != "mil_box") then {"title_D" setMarkerType "mil_box"};
};
////////////////////////////////////////////////////////////////////////////////////////





//////////////////// Script Cap /////////////////////////////////////////////////////////////
if (cap_active_D) then {

	// Qui controle ?
	
	// Zone Neutre
	if (control_D == 0) then {
		if (score_D == 100) then {control_D = 1; "title_D" setMarkerColor "ColorBlue"}; // zone cap par Att
		if (score_D == -100) then {control_D = -1; "title_D" setMarkerColor "ColorRed"}; // zone cap par Def
	};
	
	// Zone capé
	if ((control_D == 1) && (score_D <= 0)) then {control_D = 0; "title_D" setMarkerColor "ColorBlack"}; // zone perdu par ATT, devient neutre
	if ((control_D == -1) && (score_D >= 0)) then {control_D = 0; "title_D" setMarkerColor "ColorBlack"}; // zone perdu par DEF, devient neutre
	

	
	// CAP
	
	// Att > Def
	if (score_D < 100) then {
		if ((att_side countside list trigger_D) > (def_side countside list trigger_D)) then {
			_nb_att = ((att_side countside list trigger_D) - (def_side countside list trigger_D));
			score_D = score_D + _nb_att;
			if (score_D > 100) then {score_D = 100}; // on ne dépasse pas 100
		};
	};
	
	// Def > Att
	if (score_D > -100) then {
		if ((def_side countside list trigger_D) > (att_side countside list trigger_D)) then {
			_nb_def = ((def_side countside list trigger_D) - (att_side countside list trigger_D));
			score_D = score_D - _nb_def;
			if (score_D < -100) then {score_D = -100}; // on ne dépasse pas -100
		};
	};
	
	
	
	// Couleur markeur 
	if (score_D < 0) then {  // zone cap par DEF
		_alpha = score_D / -200;  
		"zone_D" setMarkerAlpha _alpha; 
		"zone_D" setMarkerColor "ColorRed"
	};
			
	if (score_D > 0) then {  // zone cap par ATT
		_alpha = score_D / 200;  
		"zone_D" setMarkerAlpha _alpha; 
		"zone_D" setMarkerColor "ColorBlue"
	};
	
	if (score_D == 0) then {  // Neutre invisible.
	"zone_D" setMarkerAlpha 0;
	"title_D" setMarkerColor "ColorBlack";
	};

	
}; 


};